feat(tuned): migrate sysctl tunings to tuned #2082
Draft
Conversation
… GIDs - Move various sysctl parameters from setup-system.yml into the postgresql tuned profile. - Explicitly define GIDs for ssl-cert (1001) and postgres (1002) to ensure stable HugePages access. - Add HugePages calculation and hugetlb_shm_group configuration to the tuned profile. - Ensure gotrue.service waits for tuned.service before starting.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates host kernel/sysctl tunings from direct Ansible sysctl tasks to a dedicated tuned profile, aiming to centralize and avoid conflicts while improving PostgreSQL-oriented performance and stability.
Changes:
- Updated PostgreSQL package release strings to
*-tuned-1variants. - Added/expanded
tunedprofile configuration for PostgreSQL, including a base profile include, Supabase-specific sysctls, and HugePages settings. - Removed direct sysctl tuning from
setup-system.yml, added deterministic GIDs for postgres-related groups innixpkg_mode, and ordered gotrue after tuned.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ansible/vars.yml | Updates Postgres release identifiers to tuned-specific builds. |
| ansible/tasks/setup-tuned.yml | Creates/activates a tuned profile and writes sysctl/HugePages tuning into tuned.conf. |
| ansible/tasks/setup-system.yml | Removes direct sysctl configuration now intended to be handled by tuned. |
| ansible/tasks/setup-postgres.yml | Sets deterministic GIDs for ssl-cert and postgres groups in nixpkg_mode. |
| ansible/files/gotrue.service.j2 | Ensures gotrue starts after tuned to apply kernel/network tunings first. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Install and configure tuned when stage2_nix | ||
| - name: tuned - Install and configure tuned when stage2_nix | ||
| when: | ||
| - (stage2_nix or nixpkg_mode) |
| path: '/etc/tuned/profiles/postgresql/tuned.conf' | ||
| section: 'sysctl' | ||
| state: 'present' | ||
| value: "{{ (shared_buffers * overhead) / hugepagesize | round | int }}" |
Comment on lines
+215
to
+218
| vars: | ||
| hugepagesize: 2048 # assumes a 2MB page | ||
| shared_buffers: 131072 # we use 128MB (128 * 1024) of shared_buffers by default | ||
| overhead: 1.05 |
Comment on lines
+226
to
+230
| option: 'vm.hugetlb_shm_group' | ||
| path: '/etc/tuned/profiles/postgresql/tuned.conf' | ||
| section: 'sysctl' | ||
| state: 'present' | ||
| value: '1002' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Ansible Task Refactoring (ansible/tasks/):
postgres,platform, andsaltrepos for existingsysctlcalls.Service Ordering (ansible/files/gotrue.service.j2):
Detailed Analysis of Sysctl Parameters
The following sysctl parameters are now being applied via tuned. These changes generally aim to optimize for a high-throughput database workload, improve network resilience, and prevent memory exhaustion issues.
vm.overcommit_memory = 2: Tells the kernel to never overcommit memory. This is a safer mode for dedicated database servers, ensuring the OOM killer is less likely to trigger unpredictably, though it requires careful sizing of Swap + RAM.Conclusion
These changes represent a move towards a "production-ready," high-performance configuration. The system is explicitly tuned for high throughput (via buffer/window increases), stability (via OOM panic policies), and reduced CPU overhead (via HugePages and NUMA settings). These settings were based on existing Supabase settings throughout the code, and the recommended tuning practices from Red Hat: PostgreSQL Load Tuning on RHEL (https://www.redhat.com/en/blog/postgresql-load-tuning-red-hat-enterprise-linux). This ensures that the OS is not just a general-purpose host, but is specifically optimized for the high-concurrency, high-I/O profile of a production PostgreSQL instance.